/**
 * 给定H1:M1和H2:M2，计算时间差
 */
#include <bits/stdc++.h>
using namespace std;

#include <bits/extc++.h>
using namespace __gnu_pbds;

char *__abc147, *__xyz258, __ma369[1000000];
#define __hv007() ((__abc147==__xyz258) && (__xyz258=(__abc147=__ma369)+fread(__ma369,1,100000,stdin),__abc147==__xyz258) ? EOF : *__abc147++)

int getInt(){
	int sgn = 1;
	char ch = __hv007();
	while( ch != '-' && ( ch < '0' || ch > '9' ) ) ch = __hv007();
	if ( '-' == ch ) {sgn = 0;ch=__hv007();}
 
	int ret = (int)(ch-'0');
	while( '0' <= (ch=__hv007()) && ch <= '9' ) ret = ret * 10 + (int)(ch-'0');
	return sgn ? ret : -ret;
}




using llt = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;

int H1, M1, H2, M2;

void proc(){
    if(H1 == H2 and M1 == M2) return (void)(cout << "24 0" << "\n");
    if(H2 < H1 or (H2 == H1 and M2 < M1)) H2 += 24;

    auto m = M2 - M1;
    if(m < 0) m += 60, H2 -= 1;
    auto h = H2 - H1;
    cout << h << " " << m << "\n";
}

int main(){
#ifndef ONLINE_JUDGE
    freopen("z.txt", "r", stdin);
#endif
    ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(0);
    int nofkase = 1;
    cin >> nofkase;
    while(nofkase--){
        cin >> H1 >> M1 >> H2 >> M2;
        proc();
    }
    return 0;
}